<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

/**
 * 分类验证
 */
class CategoryRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'cate_name' => 'required',
            'pid' => 'required|regex:/^\d+$/'
        ];
    }
    
    /**
     * 错误消息
     * @return array
     */
    public function messages() {
       return [
           'cate_name.required' => '分类名称必须填写',
           'pid.required' => '必须要选择上级分类',
           'pid.regex' => '上级分类错误'
       ];
    }
}
